/**
 * 
 */
package weibo4j.examples;

import weibo4j.Friendships;
import weibo4j.Search;
import weibo4j.Users;
import weibo4j.examples.oauth2.Log;
import weibo4j.http.HttpClient;
import weibo4j.model.PostParameter;
import weibo4j.model.User;
import weibo4j.model.UserWapper;
import weibo4j.model.WeiboException;
import weibo4j.org.json.JSONArray;
import weibo4j.org.json.JSONObject;
import weibo4j.util.WeiboConfig;

/**
 * 注册
 * @author Administrator
 * 
 */
public class WeiboRelation {
	public static UserWapper getFollowersByUid(String access_token,String uid,int count,int cursor){
		HttpClient client = new HttpClient();
		client.setToken(access_token);
		UserWapper wapper=null;
		try {
			wapper = User.constructWapperUsers(client.get(
					WeiboConfig.getValue("baseURL") + "friendships/followers.json",
					new PostParameter[] { new PostParameter("uid", uid),
					new PostParameter("count", count),
					new PostParameter("cursor", cursor),
					new PostParameter("trim_status", 0)}));
		} catch (WeiboException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return wapper;
	}
	//获取用户关注的用户列表和详细信息 
	//count 单页返回的记录条数，默认为50，最大不超过200
	//cursor 根据count向前取多少条记录
	public static UserWapper getFriendsByUid(String access_token,String uid,int count,int cursor){
		HttpClient client = new HttpClient();
		client.setToken(access_token);
		UserWapper wapper=null;
		try {
			wapper = User.constructWapperUsers(client.get(
					WeiboConfig.getValue("baseURL") + "friendships/friends.json",
					new PostParameter[] { new PostParameter("uid", uid),
					new PostParameter("count", count),
					new PostParameter("cursor", cursor),
					new PostParameter("trim_status", 0)}));
		} catch (WeiboException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return wapper;
	}
	//获取用户关注的用户UID列表 
	//count 单页返回的记录条数，默认为500，最大不超过5000。 
	//cursor 根据count向前取多少条记录
	public static String[] getFriendsIdsByUid(String access_token,String uid,int count,int cursor){
		Friendships fm = new Friendships();
		fm.client.setToken(access_token);
		String[] ids =null;
		try {
			ids = fm.getFriendsIdsByUid(uid,count,cursor);
			for(String s : ids){
				Log.logInfo(s);
			}
			System.out.println(ids.length);
		} catch (WeiboException e) {
			e.printStackTrace();
		}
		return ids;
	}
	public static String[] getFriendsIdsByName(String access_token,String name,int count,int cursor){
		Friendships fm = new Friendships();
		fm.client.setToken(access_token);
		String[] ids =null;
		try {
			ids = fm.getFriendsIdsByName(name,count,cursor);
			for(String s : ids){
				Log.logInfo(s);
			}
			System.out.println(ids.length);
		} catch (WeiboException e) {
			e.printStackTrace();
		}
		return ids;
	}
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		String access_token = WeiboContants.access_token;
		String uid =WeiboContants.uid;
		String domain =WeiboContants.domain;
		//getFriendsIdsByUid(access_token,"2576818560",500,1900);
		getFriendsByUid(access_token,"2576818560",200,0);
	}

}
